﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class BookList : System.Web.UI.Page
{
    public IQueryable getDataSource()
    {
        LINQDataContext bookDB = new LINQDataContext();
        var book_list = from a in bookDB.GetTable<Book>()
                        where a.Catalogue == DropDownList1.SelectedValue
                        select a;
        return book_list;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
       
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
    protected void summit_Click(object sender, EventArgs e)
    {
      }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
   {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        search.Text = "";
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        if (Session.GetCurrentUser() != "Admin")
            Response.Redirect("~/Login/Permission.aspx");
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            Response.Redirect("BookInformation.aspx?BookID="+ e.CommandArgument);
        }
        if (e.CommandName == "dele")
        {
            if (Session.GetCurrentUser( ) == "Admin")
            {
                LINQDataContext lin = new LINQDataContext( );

                var iss = from a in lin.GetTable<Book>( )
                          where a.BookID.ToString( ) == e.CommandArgument.ToString( )
                          select a;
                try
                {
                    foreach (Book d in iss)
                    {
                        lin.Books.DeleteOnSubmit( d );
                        lin.SubmitChanges( );
                        GridView1.DataBind( );
                    }
                }
                catch
                {
                    Response.Redirect( "SQLError.aspx" );
                }
            }

            
        }
    }
}